"""
设计一个函数，产生指定长度的验证码，验证码由大小写字母和数字组成

Version: 0.1
Author: yuwl
Date：2024-3-19
"""
import random

def generate_code(code_len=4):
    all_chars = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'
    last_pos = len(all_chars) - 1
    code = ''
    for _ in range(code_len):
        index = random.randint(0, last_pos)
        code += all_chars[index]
    return code

print(generate_code(6))